package com.framework.exception.advice;

import com.framework.exception.common.R;
import com.framework.exception.exception.BusinessException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionAdvice {

    /**
     * 自定义业务全局处理异常
     * @param e Business
     * @return
     */
    @ExceptionHandler(value = BusinessException.class)
    public R businessExceptionHandler(BusinessException e) {
        return R.error(e.getCode(), e.getMsg());
    }

    /**
     * 默认全局异常
     * @param e Exception
     * @return
     */
    @ExceptionHandler(value = Exception.class)
    public R exceptionHandler(Exception e) {
        return R.error(500, e.getMessage());
    }
}
